package edu.zju.gis.dldsj.type;

import lombok.Getter;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author yanlo yanlong_lee@qq.com
 * @version 1.0 2018/07/12
 * Comments 描述字段名称、类型、默认值等信息
 */
@Getter
@Setter
public class StructField implements Serializable {
    private String name;
    private DataType dataType;
    private boolean nullable;
    private Object defaultValue;

    public StructField(String name, DataType dataType) {
        this(name, dataType, true);
    }

    public StructField(String name, DataType dataType, boolean nullable) {
        this(name, dataType, nullable, dataType.getDefaultValue());
    }

    public StructField(String name, DataType dataType, boolean nullable, Object defaultValue) {
        if (!nullable && defaultValue == null)
            throw new IllegalArgumentException("cannot set defaultValue to null when nullable is false");
        this.name = name;
        this.dataType = dataType;
        this.nullable = nullable;
        this.defaultValue = defaultValue;
    }

    @Override
    public String toString() {
        return "StructField{" +
                "name='" + name + '\'' +
                ", dataType=" + dataType +
                ", nullable=" + nullable +
                ", defaultValue=" + defaultValue +
                '}';
    }
}
